package org.locker.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.locker.domain.bo.WechatMpUserBo;
import org.locker.domain.vo.WechatMpUserVo;
import org.locker.service.IWechatMpUserService;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.locker.common.idempotent.annotation.RepeatSubmit;
import org.locker.common.log.annotation.Log;
import org.locker.common.web.core.BaseController;
import org.locker.common.mybatis.core.page.PageQuery;
import org.locker.common.core.domain.R;
import org.locker.common.core.validate.AddGroup;
import org.locker.common.core.validate.EditGroup;
import org.locker.common.log.enums.BusinessType;
import org.locker.common.excel.utils.ExcelUtil;
import org.locker.common.mybatis.core.page.TableDataInfo;

/**
 * 系统参数
 *
 * @author winnie
 * @date 2024-05-21
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/device/wechatMpUser")
public class WechatMpUserController extends BaseController {

    private final IWechatMpUserService wechatMpUserService;

    /**
     * 查询系统参数列表
     */
    @SaCheckPermission("device:wechatMpUser:list")
    @GetMapping("/list")
    public TableDataInfo<WechatMpUserVo> list(WechatMpUserBo bo, PageQuery pageQuery) {
        return wechatMpUserService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出系统参数列表
     */
    @SaCheckPermission("device:wechatMpUser:export")
    @Log(title = "系统参数", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(WechatMpUserBo bo, HttpServletResponse response) {
        List<WechatMpUserVo> list = wechatMpUserService.queryList(bo);
        ExcelUtil.exportExcel(list, "系统参数", WechatMpUserVo.class, response);
    }

    /**
     * 获取系统参数详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("device:wechatMpUser:query")
    @GetMapping("/{id}")
    public R<WechatMpUserVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(wechatMpUserService.queryById(id));
    }

    /**
     * 新增系统参数
     */
    @SaCheckPermission("device:wechatMpUser:add")
    @Log(title = "系统参数", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody WechatMpUserBo bo) {
        return toAjax(wechatMpUserService.insertByBo(bo));
    }

    /**
     * 修改系统参数
     */
    @SaCheckPermission("device:wechatMpUser:edit")
    @Log(title = "系统参数", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody WechatMpUserBo bo) {
        return toAjax(wechatMpUserService.updateByBo(bo));
    }

    /**
     * 删除系统参数
     *
     * @param ids 主键串
     */
    @SaCheckPermission("device:wechatMpUser:remove")
    @Log(title = "系统参数", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(wechatMpUserService.deleteWithValidByIds(List.of(ids), true));
    }
}
